<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Services\Admin\MenuService;
use App\Http\Requests\Admin\MenuRequest;

class MenuController extends Controller
{
    public function routes()
    {

        $data = MenuService::routes();

        return $this->success(data: $data);
    }

    public function options(Request $request)
    {

        $onlyParent = $request->input('onlyParent');

        $data = MenuService::options($onlyParent);
        return $this->success(data: $data);
    }

    /**
     * 显示资源列表。
     */
    public function index(Request $request)
    {

        $params = $request->only('keywords');

        $data = MenuService::index($params);

        return $this->success(data: $data);
    }

    /**
     * 将新创建的资源存储到数据库。
     */
    public function store(MenuRequest $request)
    {
        $validated = $request->validated();

        $data = MenuService::store($validated);

        return $this->success(data: $data);
    }

    /**
     * 显示指定资源的详细信息。
     */
    public function show(string $id)
    {
        $data = MenuService::show($id);

        return $this->success(data: $data);
    }

    /**
     * 更新指定资源。
     */
    public function update(MenuRequest $request, string $id)
    {
        $validated = $request->validated();

        $data = MenuService::update($validated, $id);

        return $this->success(data: $data);
    }

    /**
     * 删除指定资源。
     */
    public function destroy(string $id)
    {
        $data = MenuService::destroy($id);

        return $this->success(data: $data);
    }
}
